package o;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.updatemanager.impl.fileinfo.dao.AppFileInfo;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class dam {

    static class c extends AsyncTask<Void, Void, Void> {
        private String ˊ;

        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ˊ((Void[]) objArr);
        }

        public c(String str) {
            this.ˊ = str;
        }

        protected Void ˊ(Void... voidArr) {
            euc.ˊ().ॱ();
            PackageInfo ˏ = dnx.ˏ(this.ˊ, ContentManager.getInstant().getContext());
            if (!(ˏ == null || ˏ.applicationInfo == null)) {
                AppFileInfo appFileInfo = new AppFileInfo();
                appFileInfo.ˋ(this.ˊ);
                appFileInfo.ˏ(ˏ.versionCode);
                File file = new File(ˏ.applicationInfo.sourceDir);
                appFileInfo.ˏ(dnw.ˎ(ˏ.applicationInfo.sourceDir, AaidIdConstant.SIGNATURE_SHA256));
                appFileInfo.ˏ(file.lastModified());
                dal.ˎ().ˏ(appFileInfo);
                List ˋ = das.ˋ(ˏ);
                int i = 0;
                if (ˋ != null) {
                    i = ˋ.size();
                }
                czi.ˎ.ˋ("AppFileInfoManager", "getAppFileHash and KeySetss:" + i);
            }
            euc.ˊ().ˏ();
            return null;
        }
    }

    static class d extends AsyncTask<Void, Void, Void> {
        private String ˊ;

        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ˊ((Void[]) objArr);
        }

        public d(String str) {
            this.ˊ = str;
        }

        protected Void ˊ(Void... voidArr) {
            euc.ˊ().ॱ();
            dal.ˎ().ॱ(this.ˊ);
            dar.ˏ().ˊ(this.ˊ);
            czi.ˎ.ˋ("AppFileInfoManager", "delete AppFileInfo & AppKeySets:" + this.ˊ);
            euc.ˊ().ˏ();
            return null;
        }
    }

    public static AppFileInfo ˏ(String str, int i) {
        List ˋ = dal.ˎ().ˋ(str, i);
        if (ˋ != null) {
            if (1 == ˋ.size()) {
                return (AppFileInfo) ˋ.get(0);
            }
            if (ˋ.size() > 1) {
                czi.ˎ.ˋ("AppFileInfoManager", "too many AppFileInfo of " + str);
                dal.ˎ().ॱ(str);
            }
        }
        return null;
    }

    public static List<AppFileInfo> ˊ() {
        return dal.ˎ().ˋ();
    }

    public static void ॱ(String str) {
        new c(str).executeOnExecutor(dso.ˊ, new Void[0]);
    }

    public static void ˋ(String str) {
        new d(str).executeOnExecutor(dso.ˊ, new Void[0]);
    }

    public static void ˋ() {
        List<Object> ˋ = dal.ˎ().ˋ();
        ArrayList arrayList = new ArrayList();
        Collection ˎ = ((czu) dbn.ˎ(czu.class)).ˎ(false, 0);
        Collection ˏ = ((czu) dbn.ˎ(czu.class)).ˏ(false, 0);
        arrayList.addAll(ˎ);
        arrayList.addAll(ˏ);
        PackageManager packageManager = ContentManager.getInstant().getContext().getPackageManager();
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            ApkUpgradeInfo apkUpgradeInfo = (ApkUpgradeInfo) it.next();
            try {
                PackageInfo packageInfo = packageManager.getPackageInfo(apkUpgradeInfo.ᐝ(), 64);
                if (packageInfo == null) {
                    czi.ˎ.ˊ("AppFileInfoManager", "pi is null, apkUpgradeInfo.package_ = " + apkUpgradeInfo.ᐝ());
                } else if (packageInfo.applicationInfo != null) {
                    File file = new File(packageInfo.applicationInfo.sourceDir);
                    for (Object obj : ˋ) {
                        if (apkUpgradeInfo.ᐝ().equals(obj.ॱ()) && apkUpgradeInfo.ᐝॱ() == obj.ˎ() && obj.ˊ() == file.lastModified()) {
                            break;
                        }
                    }
                    Object obj2 = null;
                    if (obj2 != null) {
                        ˋ.remove(obj2);
                    } else {
                        AppFileInfo appFileInfo = new AppFileInfo();
                        appFileInfo.ˋ(apkUpgradeInfo.ᐝ());
                        appFileInfo.ˏ(packageInfo.versionCode);
                        appFileInfo.ˏ(dnw.ˎ(packageInfo.applicationInfo.sourceDir, AaidIdConstant.SIGNATURE_SHA256));
                        appFileInfo.ˏ(file.lastModified());
                        dal.ˎ().ˏ(appFileInfo);
                        czi.ˎ.ˋ("AppFileInfoManager", "create app md5, packageName = " + apkUpgradeInfo.ᐝ());
                    }
                }
            } catch (NameNotFoundException e) {
                czi.ˎ.ˋ("AppFileInfoManager", "updateBatchApkHash exception: " + e.toString());
            }
        }
    }
}
